package com.wuxiaofan.listener;

import com.wuxiaofan.event.LogEvent;
import com.wuxiaofan.event.NoteEvent;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class NoteListener{

    @Async
    @SneakyThrows
    @EventListener(NoteEvent.class)
    public void onApplicationEvent(NoteEvent event) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        String context = event.getContext();

        log.info("context:{}",context);
    }
}
